class Base62Helper {
  Base62Helper._();
  static const characters =
      '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  static String decimalToBase62(int decimal) {
    String base62 = '';

    while (decimal > 0) {
      base62 = characters[decimal % 62] + base62;
      decimal ~/= 62;
    }

    return base62.isEmpty ? '0' : base62;
  }

  static int base62ToDecimal(String base62) {
    int decimal = 0;

    for (int i = 0; i < base62.length; i++) {
      decimal = decimal * 62 + characters.indexOf(base62[i]);
    }

    return decimal;
  }
}
